// 属性管理api

import request from '@/utils/request.ts'
import type { ResponseData } from '@/api/type.ts'
import type { Category, Attr } from '@/api/product/attr/type.ts'

enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2',
  C3_URL = '/admin/product/getCategory3',
  ATTR_URL = '/admin/product/attrInfoList',
  ATTR_SAVE_URL = '/admin/product/saveAttrInfo',
  ATTR_DELETE_URL = '/admin/product/deleteAttr',
}

export const reqC1 = () => {
  return request.get<any, ResponseData<Category[]>>(API.C1_URL)
}

export const reqC2 = (id: number) => {
  return request.get<any, ResponseData<Category[]>>(API.C2_URL + '/' + id)
}

export const reqC3 = (id: number) => {
  return request.get<any, ResponseData<Category[]>>(API.C3_URL + '/' + id)
}

export const reqAttrList = (c1: number, c2: number, c3: number) => {
  return request.get<any, ResponseData<Attr[]>>(
    `${API.ATTR_URL}/${c1}/${c2}/${c3}`,
  )
}

export const reqSaveAttr = (attr: Attr) => {
  return request.post<any, ResponseData<any>>(API.ATTR_SAVE_URL, attr)
}

export const reqDeleteAttr = (id: number) => {
  return request.delete<any, ResponseData<any>>(`${API.ATTR_DELETE_URL}/${id}`)
}
